package com.appcenter.application.controller;

import com.appcenter.application.input.orgJob.*;
import com.appcenter.application.service.OrgJobService;
import com.appcenter.jz.config.ErrorJsonResult;
import com.appcenter.jz.config.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("api/services/jzappcenter/orgjob")
@Api("组织岗位相关API")
public class OrgJobController {
    @Autowired
    OrgJobService orgJobService;

 @ApiOperation(value = "加载组织岗位", notes = "加载组织岗位", produces = "application/json")
 @PostMapping("/pageLoad")
 public ResponseEntity<JsonResult> PageLoad(@RequestBody PageLoadInput input) throws Exception {
     //throw new ErrorJsonResult("1000001", "捕获异常信息");
     JsonResult r = new JsonResult();
     try {
         r.setResult(orgJobService.PageLoad(input));

     } catch (ErrorJsonResult e) {
         r.setResult(e.getClass().getName() + ":" + e.getMessage());
         r.setError(e);
         e.printStackTrace();
         return ResponseEntity.status(500).body(r);
     }
     return ResponseEntity.ok(r);
 }

 @ApiOperation(value = "查询组织岗位", notes = "查询组织岗位", produces = "application/json")
 @PostMapping("/getorgjobs")
 public ResponseEntity<JsonResult> getOrgJobs(@RequestBody GetOrgJobsInput input) throws Exception {
     //throw new ErrorJsonResult("1000001", "捕获异常信息");
     JsonResult r = new JsonResult();
     try {
         r.setResult(orgJobService.GetOrgJobs(input));

     } catch (ErrorJsonResult e) {
         r.setResult(e.getClass().getName() + ":" + e.getMessage());
         r.setError(e);
         e.printStackTrace();
         return ResponseEntity.status(500).body(r);
     }
     return ResponseEntity.ok(r);
 }

    @ApiOperation(value = "部门岗位人员设置", notes = "部门岗位人员设置", produces = "application/json")
    @PostMapping("/createorgjob")
    public ResponseEntity<JsonResult> CreateOrgJob(@RequestBody CreateOrgJobInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgJobService.CreateOrgJob(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }

    @ApiOperation(value = "部门岗位人员修改", notes = "部门岗位人员修改", produces = "application/json")
    @PostMapping("/editorgjob")
    public ResponseEntity<JsonResult> EditOrgJob(@RequestBody EditOrgJobInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgJobService.EditOrgJob(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
    @ApiOperation(value = "部门岗位删除", notes = "部门岗位删除", produces = "application/json")
    @PostMapping("/deleteorgJob")
    public ResponseEntity<JsonResult> DeleteOrgJob(@RequestBody DeleteOrgJobInput input) throws Exception {
        //throw new ErrorJsonResult("1000001", "捕获异常信息");
        JsonResult r = new JsonResult();
        try {
            r.setResult(orgJobService.DeleteOrgJob(input));

        } catch (ErrorJsonResult e) {
            r.setResult(e.getClass().getName() + ":" + e.getMessage());
            r.setError(e);
            e.printStackTrace();
            return ResponseEntity.status(500).body(r);
        }
        return ResponseEntity.ok(r);
    }
}
